﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using QuanLyBanHang.DataConnection;
using System.Windows.Forms;

namespace QuanLyBanHang.QuerySQL
{
    class ClassNguoidung
    {
        Connect conn = new Connect();
        //Lấy về bảng
        public DataTable ShowUser()
        {
            DataTable dt = new DataTable();
            try
            {
                String sql = "select *from NGUOIDUNG";
                dt = conn.getTable(sql);
            }catch(Exception e){
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return dt;
        }
        public DataTable ShowMANV()
        {
            DataTable dt = new DataTable();
            try
            {
                String sql = "select MANV from NHANVIEN";
                dt = conn.getTable(sql);
            }catch(Exception e){
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return dt;
        }
        public DataTable ShowMAQUYEN()
        {
            DataTable dt = new DataTable();
            try
            {
                String sql = "select *from QUYEN";
                dt = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return dt;
        }
        public DataTable Showtaikhoan()
        {
            DataTable dt = new DataTable();
            try
            {
                String sql = "select ID from NGUOIDUNG";
                dt = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return dt;
        }
        public DataTable Timkiem(string tk)
        {
            DataTable dt = new DataTable();
            try
            {
                String sql = "select *from NGUOIDUNG where ID like '%" + tk + "%'";
                dt = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return dt;
        }
        //Thêm sửa xóa
        public void themnguoidung(string tk, string mq, string manv, string ps)
        {
            try
            {
                string sql = "insert into NGUOIDUNG values('" + tk + "','" + mq + "','" + manv + "','" + ps + "')";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Thêm thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
        public void Xoanguoidung(string tk)
        {
            try
            {
                string sql = "delete NGUOIDUNG where ID = '" + tk + "'";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Xóa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
        public void Suatk(string tk1,string tk2, string mq, string manv, string ps)
        {
            try
            {
                string sql = "update NGUOIDUNG set ID = '" + tk2 + "', MAQUYEN = '" + mq + "', MANV = '" + manv + "', PASS = '" + ps + "' where ID = '" + tk1 + "'";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Sửa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
    }
}
